﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2_IDAL;

namespace HCQ2_DAL_MSSQL
{
    /// <summary>
    /// 订单流水号生成
    /// </summary>
    public partial class N_OrderNumberDAL: IN_OrderNumberDAL
    {
        /// <summary>
        /// 获取当前流水号
        /// </summary>
        /// <returns></returns>
        public int GetMaxOrderNumber()
        {
            string sql = "select case when MAX(OrderNum) is null then 10000 else MAX(OrderNum+1) end from N_OrderNumber where DATEDIFF(DD,CreateTime,GETDATE())=0";

            return Convert.ToInt32(HCQ2_Common.SQL.SqlHelper.ExecuteScalar(sql));
        }

        /// <summary>
        /// 添加流水号
        /// </summary>
        /// <param name="OrderNum"></param>
        public void AddOrderNumber(int OrderNum)
        {
            string sql = $"insert into N_OrderNumber (OrderNum,CreateTime) values({OrderNum},GETDATE())";
            HCQ2_Common.SQL.SqlHelper.ExecuteScalar(sql);
        }
    }
}
